<template>
  <el-card class="box-card">
    <el-form :inline="true" :model="formInline" class="demo-form-inline" :disabled="isDisable">
      <el-form-item label="一级分类">
        <el-select v-model="category1Id" placeholder="请选择">
          <el-option :label="c1.name" :value="c1.id" v-for="c1 in categoryStore.category1List" :key="c1.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select v-model="category2Id" placeholder="请选择">
          <el-option :label="c2.name" :value="c2.id" v-for="c2 in categoryStore.category2List" :key="c2.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="category3Id" placeholder="请选择">
          <el-option :label="c3.name" :value="c3.id" v-for="c3 in categoryStore.category3List" :key="c3.id" />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script lang='ts'>
export default {
  name: "CategorySelector",
};
</script>

<script setup lang="ts">
import { computed, onMounted, reactive } from "vue";
import { useCategoryListStore } from "@/stores/categoryList";
const formInline = reactive({
  user: "",
  region: "",
});

onMounted(() => {
  GetCategory1ListData();
});

//接收参数
defineProps(['isDisable'])

//获取categoryStore对象
const categoryStore = useCategoryListStore();

//获取一级分类数据
const GetCategory1ListData = async () => {
  categoryStore.getCategory1ListData();
};

//一级分类计算属性
const category1Id = computed({
  get() {
    return categoryStore.category1Id as number;
  },
  set(value: number) {
    categoryStore.getCategory2ListData(value);
  },
});

//二级分类计算属性
const category2Id = computed({
  get() {
    return categoryStore.category2Id as number;
  },
  set(value: number) {
    categoryStore.getCategory3ListData(value);
  },
});

//三级分类计算属性
const category3Id = computed({
  get() {
    return categoryStore.category3Id as number;
  },
  set(value: number) {
    categoryStore.setCategory3Id(value);
  },
});
</script>
<style></style>